
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>高级 · 千锋大前端小册-GP19-Node.js</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="古艺散人">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    

        
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="01-Node中间件.html" />
    
    
    <link rel="prev" href="../basics/06-socket.html" />
    

    
        <link rel="shortcut icon" href='../source/images/favicon.jpg' type="image/x-icon">
    
    
        <link rel="bookmark" href='../source/images/favicon.jpg' type="image/x-icon">
    
    
        <link rel="apple-touch-icon" href='../source/images/apple-touch-icon.jpg'>
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href="../source/images/apple-touch-icon.jpg">
        
        <link rel="apple-touch-icon" sizes="180x180" href="../source/images/apple-touch-icon.jpg">
        
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"lurongtao","repo":"felixbooks-kbone","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../basics/01-Node.js基础.html">
            
                <a href="../basics/01-Node.js基础.html">
            
                    
                    基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../basics/01-Node.js基础.html">
            
                <a href="../basics/01-Node.js基础.html">
            
                    
                    01-Node.js基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../basics/02-yarn.html">
            
                <a href="../basics/02-yarn.html">
            
                    
                    02-Yarn入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../basics/03-Express.html">
            
                <a href="../basics/03-Express.html">
            
                    
                    03-Express
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../basics/04-Koa2.html">
            
                <a href="../basics/04-Koa2.html">
            
                    
                    04-Koa2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../basics/05-MongoDB.html">
            
                <a href="../basics/05-MongoDB.html">
            
                    
                    05-MongoDB
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../basics/06-socket.html">
            
                <a href="../basics/06-socket.html">
            
                    
                    06-socket编程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter active" data-level="1.3" data-path="01-Node中间件.html">
            
                <a href="01-Node中间件.html">
            
                    
                    高级
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="01-Node中间件.html">
            
                <a href="01-Node中间件.html">
            
                    
                    01-Node中间件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="02-Node事件循环.html">
            
                <a href="02-Node事件循环.html">
            
                    
                    02-Node事件循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="03-Node中间层.html">
            
                <a href="03-Node中间层.html">
            
                    
                    03-Node中间层
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../thanks/">
            
                <a href="../thanks/">
            
                    
                    感谢
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >高级</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#node-&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;"><b></b>Node &#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;</a></li><ul><ul><li><span class="title-icon "></span><a href="#&#x4E00;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x6982;&#x5FF5;"><b></b>&#x4E00;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x6982;&#x5FF5;</a></li><li><span class="title-icon "></span><a href="#&#x4E8C;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;"><b></b>&#x4E8C;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;</a></li><li><span class="title-icon "></span><a href="#&#x4E09;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x793E;&#x533A;"><b></b>&#x4E09;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x793E;&#x533A;</a></li><li><span class="title-icon "></span><a href="#&#x56DB;&#x3001;&#x603B;&#x7ED3;"><b></b>&#x56DB;&#x3001;&#x603B;&#x7ED3;</a></li></ul></ul></ul></div><a href="#node-&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="node-&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;"><a name="node-&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;" class="anchor-navigation-ex-anchor" href="#node-&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="node-&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;" class="plugin-anchor" href="#node-&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>Node &#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;</h1>
<p>&#x7406;&#x89E3; Node.js &#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x4EE3;&#x7801;&#x7684;&#x5B9E;&#x73B0;&#xFF0C;&#x52A0;&#x6DF1;&#x5BF9;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x7684;&#x7406;&#x89E3;&#xFF0C;&#x6709;&#x52A9;&#x4E8E;&#x66F4;&#x597D;&#x7684;&#x4F7F;&#x7528;&#x548C;&#x7F16;&#x5199;&#x4E2D;&#x95F4;&#x4EF6;&#x3002;</p>
<h3 id="&#x4E00;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x6982;&#x5FF5;"><a name="&#x4E00;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x6982;&#x5FF5;" class="anchor-navigation-ex-anchor" href="#&#x4E00;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4E00;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x6982;&#x5FF5;" class="plugin-anchor" href="#&#x4E00;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x6982;&#x5FF5;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E00;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x6982;&#x5FF5;</h3>
<p>&#x5728; <code>Node.js</code> &#x4E2D;&#xFF0C;&#x4E2D;&#x95F4;&#x4EF6;&#x4E3B;&#x8981;&#x662F;&#x6307;&#x5C01;&#x88C5;&#x6240;&#x6709; <code>Http</code> &#x8BF7;&#x6C42;&#x7EC6;&#x8282;&#x5904;&#x7406;&#x7684;&#x65B9;&#x6CD5;&#x3002;&#x4E00;&#x6B21; <code>Http</code> &#x8BF7;&#x6C42;&#x901A;&#x5E38;&#x5305;&#x542B;&#x5F88;&#x591A;&#x5DE5;&#x4F5C;&#xFF0C;&#x5982;&#x8BB0;&#x5F55;&#x65E5;&#x5FD7;&#x3001;<code>ip</code> &#x8FC7;&#x6EE4;&#x3001;&#x67E5;&#x8BE2;&#x5B57;&#x7B26;&#x4E32;&#x3001;&#x8BF7;&#x6C42;&#x4F53;&#x89E3;&#x6790;&#x3001;<code>Cookie</code> &#x5904;&#x7406;&#x3001;&#x6743;&#x9650;&#x9A8C;&#x8BC1;&#x3001;&#x53C2;&#x6570;&#x9A8C;&#x8BC1;&#x3001;&#x5F02;&#x5E38;&#x5904;&#x7406;&#x7B49;&#xFF0C;&#x4F46;&#x5BF9;&#x4E8E; <code>Web</code> &#x5E94;&#x7528;&#x800C;&#x8A00;&#xFF0C;&#x5E76;&#x4E0D;&#x5E0C;&#x671B;&#x63A5;&#x89E6;&#x5230;&#x8FD9;&#x4E48;&#x591A;&#x7EC6;&#x8282;&#x6027;&#x7684;&#x5904;&#x7406;&#xFF0C;&#x56E0;&#x6B64;&#x5F15;&#x5165;&#x4E2D;&#x95F4;&#x4EF6;&#x6765;&#x7B80;&#x5316;&#x548C;&#x9694;&#x79BB;&#x8FD9;&#x4E9B;&#x57FA;&#x7840;&#x8BBE;&#x65BD;&#x4E0E;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x4E4B;&#x95F4;&#x7684;&#x7EC6;&#x8282;&#xFF0C;&#x8BA9;&#x5F00;&#x53D1;&#x8005;&#x80FD;&#x591F;&#x5173;&#x6CE8;&#x5728;&#x4E1A;&#x52A1;&#x7684;&#x5F00;&#x53D1;&#x4E0A;&#xFF0C;&#x4EE5;&#x8FBE;&#x5230;&#x63D0;&#x5347;&#x5F00;&#x53D1;&#x6548;&#x7387;&#x7684;&#x76EE;&#x7684;&#x3002;</p>
<p>&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x884C;&#x4E3A;&#x6BD4;&#x8F83;&#x7C7B;&#x4F3C; <code>Java</code> &#x4E2D;&#x8FC7;&#x6EE4;&#x5668;&#x7684;&#x5DE5;&#x4F5C;&#x539F;&#x7406;&#xFF0C;&#x5C31;&#x662F;&#x5728;&#x8FDB;&#x5165;&#x5177;&#x4F53;&#x7684;&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x4E4B;&#x524D;&#xFF0C;&#x5148;&#x8BA9;&#x8FC7;&#x6EE4;&#x5668;&#x5904;&#x7406;&#x3002;&#x5B83;&#x7684;&#x5DE5;&#x4F5C;&#x6A21;&#x578B;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#x3002;</p>
<p><img src="https://upload-images.jianshu.io/upload_images/15842055-dde4fe84cd4282c0.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp" alt="img"></p>
<h3 id="&#x4E8C;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;"><a name="&#x4E8C;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;" class="anchor-navigation-ex-anchor" href="#&#x4E8C;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4E8C;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;" class="plugin-anchor" href="#&#x4E8C;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E8C;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;</h3>
<p>&#x4E2D;&#x95F4;&#x4EF6;&#x662F;&#x4ECE; <code>Http</code> &#x8BF7;&#x6C42;&#x53D1;&#x8D77;&#x5230;&#x54CD;&#x5E94;&#x7ED3;&#x675F;&#x8FC7;&#x7A0B;&#x4E2D;&#x7684;&#x5904;&#x7406;&#x65B9;&#x6CD5;&#xFF0C;&#x901A;&#x5E38;&#x9700;&#x8981;&#x5BF9;&#x8BF7;&#x6C42;&#x548C;&#x54CD;&#x5E94;&#x8FDB;&#x884C;&#x5904;&#x7406;&#xFF0C;&#x56E0;&#x6B64;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x5F62;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> middleware = (req, res, next) =&gt; {
  <span class="hljs-comment">// TODO</span>
  next()
}
</code></pre>
<p>&#x4EE5;&#x4E0B;&#x901A;&#x8FC7;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x7684;&#x5B9E;&#x73B0;&#x6765;&#x7406;&#x89E3;&#x4E2D;&#x95F4;&#x4EF6;&#x662F;&#x5982;&#x4F55;&#x5DE5;&#x4F5C;&#x7684;&#x3002;</p>
<h4 id="1&#x3001;&#x65B9;&#x5F0F;&#x4E00;"><a name="1&#x3001;&#x65B9;&#x5F0F;&#x4E00;" class="anchor-navigation-ex-anchor" href="#1&#x3001;&#x65B9;&#x5F0F;&#x4E00;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="1&#x3001;&#x65B9;&#x5F0F;&#x4E00;" class="plugin-anchor" href="#1&#x3001;&#x65B9;&#x5F0F;&#x4E00;"><i class="fa fa-link" aria-hidden="true"></i></a>1&#x3001;&#x65B9;&#x5F0F;&#x4E00;</h4>
<p>&#x5982;&#x4E0B;&#x5B9A;&#x4E49;&#x4E09;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> middleware1 = (req, res, next) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware1 start&apos;</span>)
  next()
}

<span class="hljs-keyword">const</span> middleware2 = (req, res, next) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware2 start&apos;</span>)
  next()
}

<span class="hljs-keyword">const</span> middleware3 = (req, res, next) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware3 start&apos;</span>)
  next()
}
</code></pre>
<p>&#x901A;&#x8FC7;&#x9012;&#x5F52;&#x7684;&#x5F62;&#x5F0F;&#xFF0C;&#x5C06;&#x540E;&#x7EED;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x6267;&#x884C;&#x65B9;&#x6CD5;&#x4F20;&#x9012;&#x7ED9;&#x5F53;&#x524D;&#x4E2D;&#x95F4;&#x4EF6;&#xFF0C;&#x5728;&#x5F53;&#x524D;&#x4E2D;&#x95F4;&#x4EF6;&#x6267;&#x884C;&#x7ED3;&#x675F;&#xFF0C;&#x901A;&#x8FC7;&#x8C03;&#x7528; <code>next()</code> &#x65B9;&#x6CD5;&#x6267;&#x884C;&#x540E;&#x7EED;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x8C03;&#x7528;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">// &#x4E2D;&#x95F4;&#x4EF6;&#x6570;&#x7EC4;</span>
<span class="hljs-keyword">const</span> middlewares = [middleware1, middleware2, middleware3]
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">run</span> (<span class="hljs-params">req, res</span>) </span>{
  <span class="hljs-keyword">const</span> next = () =&gt; {
    <span class="hljs-comment">// &#x83B7;&#x53D6;&#x4E2D;&#x95F4;&#x4EF6;&#x6570;&#x7EC4;&#x4E2D;&#x7B2C;&#x4E00;&#x4E2A;&#x4E2D;&#x95F4;&#x4EF6;</span>
    <span class="hljs-keyword">const</span> middleware = middlewares.shift()
    <span class="hljs-keyword">if</span> (middleware) {
      middleware(req, res, next)
    }
  }
  next()
}
run() <span class="hljs-comment">// &#x6A21;&#x62DF;&#x4E00;&#x6B21;&#x8BF7;&#x6C42;&#x53D1;&#x8D77;</span>
</code></pre>
<p>&#x6267;&#x884C;&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5982;&#x4E0B;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-s">middleware1 start
middleware2 start
middleware3 start
</code></pre>
<p>&#x5982;&#x679C;&#x4E2D;&#x95F4;&#x4EF6;&#x4E2D;&#x6709;&#x5F02;&#x6B65;&#x64CD;&#x4F5C;&#xFF0C;&#x9700;&#x8981;&#x5728;&#x5F02;&#x6B65;&#x64CD;&#x4F5C;&#x7684;&#x6D41;&#x7A0B;&#x7ED3;&#x675F;&#x540E;&#x518D;&#x8C03;&#x7528; <code>next()</code> &#x65B9;&#x6CD5;&#xFF0C;&#x5426;&#x5219;&#x4E2D;&#x95F4;&#x4EF6;&#x4E0D;&#x80FD;&#x6309;&#x987A;&#x5E8F;&#x6267;&#x884C;&#x3002;&#x6539;&#x5199; <code>middleware2</code> &#x4E2D;&#x95F4;&#x4EF6;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> middleware2 = (req, res, next) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware2 start&apos;</span>)
  <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(resolve =&gt; {
    setTimeout(() =&gt; resolve(), <span class="hljs-number">1000</span>)
  }).then(() =&gt; {
    next()
  })
}
</code></pre>
<p>&#x6267;&#x884C;&#x7ED3;&#x679C;&#x4E0E;&#x4E4B;&#x524D;&#x4E00;&#x81F4;&#xFF0C;&#x4E0D;&#x8FC7;middleware3&#x4F1A;&#x5728;middleware2&#x5F02;&#x6B65;&#x5B8C;&#x6210;&#x540E;&#x6267;&#x884C;&#x3002;</p>
<p><img src="https://upload-images.jianshu.io/upload_images/15842055-62794a71064a92ed.gif?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp" alt="img"></p>
<h4 id="2&#x3001;&#x65B9;&#x5F0F;&#x4E8C;"><a name="2&#x3001;&#x65B9;&#x5F0F;&#x4E8C;" class="anchor-navigation-ex-anchor" href="#2&#x3001;&#x65B9;&#x5F0F;&#x4E8C;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="2&#x3001;&#x65B9;&#x5F0F;&#x4E8C;" class="plugin-anchor" href="#2&#x3001;&#x65B9;&#x5F0F;&#x4E8C;"><i class="fa fa-link" aria-hidden="true"></i></a>2&#x3001;&#x65B9;&#x5F0F;&#x4E8C;</h4>
<p>&#x6709;&#x4E9B;&#x4E2D;&#x95F4;&#x4EF6;&#x4E0D;&#x6B62;&#x9700;&#x8981;&#x5728;&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x524D;&#x6267;&#x884C;&#xFF0C;&#x8FD8;&#x9700;&#x8981;&#x5728;&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x540E;&#x6267;&#x884C;&#xFF0C;&#x6BD4;&#x5982;&#x7EDF;&#x8BA1;&#x65F6;&#x95F4;&#x7684;&#x65E5;&#x5FD7;&#x4E2D;&#x95F4;&#x4EF6;&#x3002;&#x5728;&#x65B9;&#x5F0F;&#x4E00;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x65E0;&#x6CD5;&#x5728; <code>next()</code> &#x4E3A;&#x5F02;&#x6B65;&#x64CD;&#x4F5C;&#x65F6;&#x518D;&#x5C06;&#x5F53;&#x524D;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x5176;&#x4ED6;&#x4EE3;&#x7801;&#x4F5C;&#x4E3A;&#x56DE;&#x8C03;&#x6267;&#x884C;&#x3002;&#x56E0;&#x6B64;&#x53EF;&#x4EE5;&#x5C06;<code>next()</code> &#x65B9;&#x6CD5;&#x7684;&#x540E;&#x7EED;&#x64CD;&#x4F5C;&#x5C01;&#x88C5;&#x6210;&#x4E00;&#x4E2A; <code>Promise</code> &#x5BF9;&#x8C61;&#xFF0C;&#x4E2D;&#x95F4;&#x4EF6;&#x5185;&#x90E8;&#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <code>next.then()</code>&#x5F62;&#x5F0F;&#x5B8C;&#x6210;&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x7ED3;&#x675F;&#x540E;&#x7684;&#x56DE;&#x8C03;&#x3002;&#x6539;&#x5199; <code>run()</code> &#x65B9;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">run</span> (<span class="hljs-params">req, res</span>) </span>{
  <span class="hljs-keyword">const</span> next = () =&gt; {
    <span class="hljs-keyword">const</span> middleware = middlewares.shift()
    <span class="hljs-keyword">if</span> (middleware) {
      <span class="hljs-comment">// &#x5C06;middleware(req, res, next)&#x5305;&#x88C5;&#x4E3A;Promise&#x5BF9;&#x8C61;</span>
      <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.resolve(middleware(req, res, next))
    }
  }
  next()
}
</code></pre>
<p>&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x8C03;&#x7528;&#x65B9;&#x5F0F;&#x9700;&#x6539;&#x5199;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> middleware1 = (req, res, next) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware1 start&apos;</span>)
  <span class="hljs-comment">// &#x6240;&#x6709;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x90FD;&#x5E94;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;Promise&#x5BF9;&#x8C61;</span>
  <span class="hljs-comment">// Promise.resolve()&#x65B9;&#x6CD5;&#x63A5;&#x6536;&#x4E2D;&#x95F4;&#x4EF6;&#x8FD4;&#x56DE;&#x7684;Promise&#x5BF9;&#x8C61;&#xFF0C;&#x4F9B;&#x4E0B;&#x5C42;&#x4E2D;&#x95F4;&#x4EF6;&#x5F02;&#x6B65;&#x63A7;&#x5236;</span>
  <span class="hljs-keyword">return</span> next().then(() =&gt; {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware1 end&apos;</span>)
  })
}
</code></pre>
<p>&#x5F97;&#x76CA;&#x4E8E; <code>async</code> &#x51FD;&#x6570;&#x7684;&#x81EA;&#x52A8;&#x5F02;&#x6B65;&#x6D41;&#x7A0B;&#x63A7;&#x5236;&#xFF0C;&#x4E2D;&#x95F4;&#x4EF6;&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x5982;&#x4E0B;&#x65B9;&#x5F0F;&#x6765;&#x5B9E;&#x73B0;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">// async&#x51FD;&#x6570;&#x81EA;&#x52A8;&#x8FD4;&#x56DE;Promise&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">const</span> middleware2 = <span class="hljs-keyword">async</span> (req, res, next) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware2 start&apos;</span>)
  <span class="hljs-keyword">await</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Promise</span>(resolve =&gt; {
    setTimeout(() =&gt; resolve(), <span class="hljs-number">1000</span>)
  })
  <span class="hljs-keyword">await</span> next()
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware2 end&apos;</span>)
}

<span class="hljs-keyword">const</span> middleware3 = <span class="hljs-keyword">async</span> (req, res, next) =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware3 start&apos;</span>)
  <span class="hljs-keyword">await</span> next()
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&apos;middleware3 end&apos;</span>)
}
</code></pre>
<p>&#x6267;&#x884C;&#x7ED3;&#x679C;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="https://upload-images.jianshu.io/upload_images/15842055-726b15e73701e39b.gif?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp" alt="img"></p>
<p>&#x4EE5;&#x4E0A;&#x63CF;&#x8FF0;&#x4E86;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x4E2D;&#x591A;&#x4E2A;&#x5F02;&#x6B65;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x8C03;&#x7528;&#x6D41;&#x7A0B;&#xFF0C;&#x5B9E;&#x9645;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x7684;&#x5B9E;&#x73B0;&#x8FD8;&#x9700;&#x8981;&#x8003;&#x8651;&#x5F02;&#x5E38;&#x5904;&#x7406;&#x3001;&#x8DEF;&#x7531;&#x7B49;&#x3002;</p>
<p>&#x5728; <code>express</code> &#x6846;&#x67B6;&#x4E2D;&#xFF0C;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x4E3A;&#x65B9;&#x5F0F;&#x4E00;&#xFF0C;&#x5E76;&#x4E14;&#x5168;&#x5C40;&#x4E2D;&#x95F4;&#x4EF6;&#x548C;&#x5185;&#x7F6E;&#x8DEF;&#x7531;&#x4E2D;&#x95F4;&#x4EF6;&#x4E2D;&#x6839;&#x636E;&#x8BF7;&#x6C42;&#x8DEF;&#x5F84;&#x5B9A;&#x4E49;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x5171;&#x540C;&#x4F5C;&#x7528;&#xFF0C;&#x4E0D;&#x8FC7;&#x65E0;&#x6CD5;&#x5728;&#x4E1A;&#x52A1;&#x5904;&#x7406;&#x7ED3;&#x675F;&#x540E;&#x518D;&#x8C03;&#x7528;&#x5F53;&#x524D;&#x4E2D;&#x95F4;&#x4EF6;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#x3002;<code>koa2</code> &#x6846;&#x67B6;&#x4E2D;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x4E3A;&#x65B9;&#x5F0F;&#x4E8C;&#xFF0C;&#x5C06; <code>next()</code> &#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x503C;&#x5C01;&#x88C5;&#x6210;&#x4E00;&#x4E2A; <code>Promise</code>&#xFF0C;&#x4FBF;&#x4E8E;&#x540E;&#x7EED;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x5F02;&#x6B65;&#x6D41;&#x7A0B;&#x63A7;&#x5236;&#xFF0C;&#x5B9E;&#x73B0;&#x4E86; <code>koa2</code> &#x6846;&#x67B6;&#x63D0;&#x51FA;&#x7684;&#x6D0B;&#x8471;&#x5708;&#x6A21;&#x578B;&#xFF0C;&#x5373;&#x6BCF;&#x4E00;&#x5C42;&#x4E2D;&#x95F4;&#x4EF6;&#x76F8;&#x5F53;&#x4E8E;&#x4E00;&#x4E2A;&#x7403;&#x9762;&#xFF0C;&#x5F53;&#x8D2F;&#x7A7F;&#x6574;&#x4E2A;&#x6A21;&#x578B;&#x65F6;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x6BCF;&#x4E00;&#x4E2A;&#x7403;&#x9762;&#x4F1A;&#x7A7F;&#x900F;&#x4E24;&#x6B21;&#x3002;</p>
<p><img src="https://upload-images.jianshu.io/upload_images/15842055-8d0fb98ad9482283.png?imageMogr2/auto-orient/strip|imageView2/2/w/1078/format/webp" alt="img"></p>
<p><code>koa2</code> &#x6846;&#x67B6;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x5B9E;&#x73B0;&#x5F97;&#x975E;&#x5E38;&#x7B80;&#x6D01;&#x548C;&#x4F18;&#x96C5;&#xFF0C;&#x8FD9;&#x91CC;&#x5B66;&#x4E60;&#x4E00;&#x4E0B;&#x6846;&#x67B6;&#x4E2D;&#x7EC4;&#x5408;&#x591A;&#x4E2A;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x6838;&#x5FC3;&#x4EE3;&#x7801;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">compose</span> (<span class="hljs-params">middleware</span>) </span>{
  <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">Array</span>.isArray(middleware)) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">TypeError</span>(<span class="hljs-string">&apos;Middleware stack must be an array!&apos;</span>)
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">const</span> fn <span class="hljs-keyword">of</span> middleware) {
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> fn !== <span class="hljs-string">&apos;function&apos;</span>) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">TypeError</span>(<span class="hljs-string">&apos;Middleware must be composed of functions!&apos;</span>)
  }
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">context, next</span>) </span>{
    <span class="hljs-keyword">let</span> index = <span class="hljs-number">-1</span>
    <span class="hljs-keyword">return</span> dispatch(<span class="hljs-number">0</span>)
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">dispatch</span> (<span class="hljs-params">i</span>) </span>{
      <span class="hljs-comment">// index&#x4F1A;&#x5728;next()&#x65B9;&#x6CD5;&#x8C03;&#x7528;&#x540E;&#x7D2F;&#x52A0;&#xFF0C;&#x9632;&#x6B62;next()&#x65B9;&#x6CD5;&#x91CD;&#x590D;&#x8C03;&#x7528;</span>
      <span class="hljs-keyword">if</span> (i &lt;= index) <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.reject(<span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">&apos;next() called multiple times&apos;</span>))
      index = i
      <span class="hljs-keyword">let</span> fn = middleware[i]
      <span class="hljs-keyword">if</span> (i === middleware.length) fn = next
      <span class="hljs-keyword">if</span> (!fn) <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.resolve()
      <span class="hljs-keyword">try</span> {
        <span class="hljs-comment">// &#x6838;&#x5FC3;&#x4EE3;&#x7801;</span>
        <span class="hljs-comment">// &#x5305;&#x88C5;next()&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x503C;&#x4E3A;Promise&#x5BF9;&#x8C61;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.resolve(fn(context, dispatch.bind(<span class="hljs-literal">null</span>, i + <span class="hljs-number">1</span>)));
      } <span class="hljs-keyword">catch</span> (err) {
        <span class="hljs-comment">// &#x9047;&#x5230;&#x5F02;&#x5E38;&#x4E2D;&#x65AD;&#x540E;&#x7EED;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x8C03;&#x7528;</span>
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">Promise</span>.reject(err)
      }
    }
  }
}
</code></pre>
<h3 id="&#x4E09;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x793E;&#x533A;"><a name="&#x4E09;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x793E;&#x533A;" class="anchor-navigation-ex-anchor" href="#&#x4E09;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x793E;&#x533A;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4E09;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x793E;&#x533A;" class="plugin-anchor" href="#&#x4E09;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x793E;&#x533A;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x4E09;&#x3001;&#x4E2D;&#x95F4;&#x4EF6;&#x793E;&#x533A;</h3>
<p>&#x5728;&#x540E;&#x7EED; <code>Node.js</code> &#x5B66;&#x4E60;&#x548C;&#x5E94;&#x7528;&#x4E2D;&#xFF0C;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528; <code>koa2</code> &#x6846;&#x67B6;&#x4F5C;&#x4E3A;&#x57FA;&#x7840;&#x6846;&#x67B6;&#xFF0C;&#x8FD9;&#x91CC;&#x5217;&#x51FA;&#x4E86;&#x4E00;&#x4E9B;&#x4F7F;&#x7528;&#x6BD4;&#x8F83;&#x591A;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x3002;</p>
<p>koa-router&#xFF1A;&#x8DEF;&#x7531;&#x4E2D;&#x95F4;&#x4EF6;
koa-bodyparser&#xFF1A;http&#x8BF7;&#x6C42;&#x4E3B;&#x4F53;&#x89E3;&#x6790;
koa-static&#xFF1A;&#x4EE3;&#x7406;&#x9759;&#x6001;&#x6587;&#x4EF6;
koa-compress&#xFF1A;gzip&#x538B;&#x7F29;
koa-logger&#xFF1A;&#x65E5;&#x5FD7;&#x8BB0;&#x5F55;
koa-convert&#xFF1A;&#x8F6C;&#x6362;koa1.x&#x7248;&#x672C;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;
kcors&#xFF1A;&#x8DE8;&#x57DF;&#x4E2D;&#x95F4;&#x4EF6;
koa&#x4E2D;&#x95F4;&#x4EF6;&#x5217;&#x8868;&#x5730;&#x5740;&#xFF1A;<a href="https://github.com/koajs/koa/wiki" target="_blank">https://github.com/koajs/koa/wiki</a></p>
<h3 id="&#x56DB;&#x3001;&#x603B;&#x7ED3;"><a name="&#x56DB;&#x3001;&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x56DB;&#x3001;&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x56DB;&#x3001;&#x603B;&#x7ED3;" class="plugin-anchor" href="#&#x56DB;&#x3001;&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x56DB;&#x3001;&#x603B;&#x7ED3;</h3>
<p>&#x672C;&#x6587;&#x4E3B;&#x8981;&#x4ECB;&#x7ECD;&#x4E86;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x6982;&#x5FF5;&#x3001;&#x4E3A;&#x4F55;&#x5F15;&#x5165;&#x4E2D;&#x95F4;&#x4EF6;&#x4EE5;&#x53CA;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x7684;&#x6838;&#x5FC3;&#x5B9E;&#x73B0;&#x3002;&#x4E2D;&#x95F4;&#x4EF6;&#x673A;&#x5236;&#x4F7F;&#x5F97; <code>Web</code> &#x5E94;&#x7528;&#x5177;&#x5907;&#x826F;&#x597D;&#x7684;&#x53EF;&#x6269;&#x5C55;&#x6027;&#x548C;&#x7EC4;&#x5408;&#x6027;&#x3002;</p>
<p>&#x5728;&#x5B9E;&#x73B0;&#x4E2D;&#x95F4;&#x4EF6;&#x65F6;&#xFF0C;&#x5355;&#x4E2A;&#x4E2D;&#x95F4;&#x4EF6;&#x5E94;&#x8BE5;&#x8DB3;&#x591F;&#x7B80;&#x5355;&#xFF0C;&#x804C;&#x8D23;&#x5355;&#x4E00;&#x3002;&#x7531;&#x4E8E;&#x6BCF;&#x4E2A;&#x8BF7;&#x6C42;&#x90FD;&#x4F1A;&#x8C03;&#x7528;&#x4E2D;&#x95F4;&#x4EF6;&#x76F8;&#x5173;&#x4EE3;&#x7801;&#xFF0C;&#x4E2D;&#x95F4;&#x4EF6;&#x7684;&#x4EE3;&#x7801;&#x5E94;&#x8BE5;&#x9AD8;&#x6548;&#xFF0C;&#x5FC5;&#x8981;&#x7684;&#x65F6;&#x5019;&#x53EF;&#x4EE5;&#x7F13;&#x5B58;&#x91CD;&#x590D;&#x83B7;&#x53D6;&#x7684;&#x6570;&#x636E;&#x3002;&#x5728;&#x5BF9;&#x4E0D;&#x540C;&#x7684;&#x8DEF;&#x7531;&#x4F7F;&#x7528;&#x4E2D;&#x95F4;&#x4EF6;&#x65F6;&#xFF0C;&#x8FD8;&#x5E94;&#x8BE5;&#x8003;&#x8651;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x4E2D;&#x95F4;&#x4EF6;&#x5E94;&#x7528;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x8DEF;&#x7531;&#x4E0A;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../basics/06-socket.html" class="navigation navigation-prev " aria-label="Previous page: 06-socket编程">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="01-Node中间件.html" class="navigation navigation-next " aria-label="Next page: 01-Node中间件">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"高级","level":"1.3","depth":1,"next":{"title":"01-Node中间件","level":"1.3.1","depth":2,"path":"advanced/01-Node中间件.md","ref":"./advanced/01-Node中间件.md","articles":[]},"previous":{"title":"06-socket编程","level":"1.2.6","depth":2,"path":"basics/06-socket.md","ref":"./basics/06-socket.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","splitter","expandable-chapters-small","anchors","github","github-buttons","sharing-plus","anchor-navigation-ex","favicon","insert-logo","livereload"],"styles":{"website":"./styles/website.css"},"pluginsConfig":{"github":{"url":"https://gitee.com/lurongtao/felixbooks-gp19-Node.js"},"livereload":{},"splitter":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"favicon":{"shortcut":"./source/images/favicon.jpg","bookmark":"./source/images/favicon.jpg","appleTouch":"./source/images/apple-touch-icon.jpg","appleTouchMore":{"120x120":"./source/images/apple-touch-icon.jpg","180x180":"./source/images/apple-touch-icon.jpg"}},"github-buttons":{"buttons":[{"user":"lurongtao","repo":"felixbooks-kbone","type":"star","size":"small","count":true}]},"expandable-chapters-small":{},"sharing":{"qq":false,"all":["google","facebook","weibo","twitter","qq","qzone","linkedin","pocket"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{},"insert-logo":{"url":"/felixbooks-gp19-node.js/images/node.js.jpg","style":"background: skyblue; width: 100%; height: 100%;"}},"theme":"default","author":"古艺散人","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"千锋大前端小册-GP19-Node.js","language":"zh-hans","links":{},"gitbook":"3.2.3","description":"Node.js复习"},"file":{"path":"advanced/01-Node中间件.md","mtime":"2020-06-25T03:15:19.980Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-07-15T09:28:56.165Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

